package com.ashin.sort;

import java.util.Arrays;

/**
 * 归并排序
 *
 * @Author: Ashin
 * @Date: 2020/9/8
 * @Description: com.ashin.sort
 * @Version: 1.0.0
 */
public class MergeSort {


    public static int[] mergeSort(int[] arr) {
        int len = arr.length;
        if (len < 2) {
            return arr;
        }
        int middle = len / 2;
        int[] left = Arrays.copyOfRange(arr, 0, middle);
        int[] right = Arrays.copyOfRange(arr, middle, len);

        return merge(mergeSort(left), mergeSort(right));
    }

    public static int[] merge(int[] left, int[] right) {
        int[] result = new int[left.length + right.length];

        while (left.length > 0 && right.length > 0) {
            if (left[0] <= right[0]) {
                //result.push(left.shift());
            } else {
                //result.push(right.shift());
            }
        }

        while (left.length > 0) {
            //result.push(left.shift());
        }

        while (right.length > 0) {
            //result.push(right.shift());
        }

        return result;
    }
}
